using System;
using System.Linq;
using System.Data;
using System.Collections.Generic;

namespace Green.AgileMapper
{
     public static partial class AgileMapperMapping
    {
        /// <summary>
        /// Green.AgileMapper.Test.StudenDto  Warp fromObj Green.AgileMapper.Test.StudenDo;
        /// </summary>
        /// <param name="domainObj">Green.AgileMapper.Test.StudenDo</param>
        /// <returns>Green.AgileMapper.Test.StudenDto</returns>
        public static  Green.AgileMapper.Test.StudenDto Warp(this Green.AgileMapper.Test.StudenDo domainObj)
        {
            var fromObj = new Green.AgileMapper.Test.StudenDto();
            fromObj.ID = domainObj.ID;
            fromObj.Name = domainObj.Name;
            fromObj.Sex = domainObj.Sex;
            if( domainObj.Address!=null )
            {
              fromObj.Country = domainObj.Address.Country;
              fromObj.Province = domainObj.Address.Province;
            }
            fromObj.Particular = domainObj.Address.Country +" 国籍 "+domainObj.Address.Province +" 省 ";
            fromObj.FirstPropertyKey = domainObj.Propertys[0].Key;
            if( domainObj.ContactWay!=null )
            {
              fromObj.ContactWay = domainObj.ContactWay.Warp();
            }
            if( domainObj.CourseIds!=null )
            {
            fromObj.CourseIds = new List<System.String>();
            foreach (var item_CourseIds in domainObj.CourseIds)
            {
                  fromObj.CourseIds.Add(item_CourseIds);
            }
            }
            if( domainObj.Propertys!=null )
            {
              fromObj.Propertys = domainObj.Propertys.Warp();
            }
            return fromObj;
        }
        
        /// <summary>
        /// Green.AgileMapper.Test.StudenDto  Warp domainObj Green.AgileMapper.Test.StudenDo;
        /// </summary>
        /// <param name="domainObj">Green.AgileMapper.Test.StudenDo</param>
        /// <returns>fromObj</returns>
        public static void Warp(this Green.AgileMapper.Test.StudenDto fromObj, Green.AgileMapper.Test.StudenDo domainObj)
        {
			if(fromObj == null )
            {
             return ;
            }
            if(domainObj == null )
            {
            domainObj = new Green.AgileMapper.Test.StudenDo();
            }
            domainObj.ID = fromObj.ID ;
            domainObj.Name = fromObj.Name ;
            domainObj.Sex = fromObj.Sex ;
            if( domainObj.Address == null )
            {
             domainObj.Address = new Green.AgileMapper.Test.Address();
            }
            domainObj.Address.Country = fromObj.Country;
            domainObj.Address.Province = fromObj.Province;

            if( domainObj.ContactWay == null )
            {
              domainObj.ContactWay = new Green.AgileMapper.Test.ContactWay();
            }
            fromObj.ContactWay.Warp(domainObj.ContactWay);
            if( fromObj.CourseIds!=null )
            {
            if( domainObj.CourseIds == null )
            {
            domainObj.CourseIds = new List<System.String>();
            }
            domainObj.CourseIds.Clear();
            foreach (var item_CourseIds in fromObj.CourseIds)
            {
                 domainObj.CourseIds.Add(item_CourseIds);
            }
            }
            if( fromObj.Propertys!=null )
            {
            if( domainObj.Propertys == null )
            {
            domainObj.Propertys = new List<Green.AgileMapper.Test.KeyValuePair>();
            }
            fromObj.Propertys.Warp(domainObj.Propertys,(fromObjItem, domainObjItem) => fromObjItem.Key==domainObjItem.Key,true);
            }

        }

        /// <summary>
        /// Green.AgileMapper.Test.StudenDto collection Warp fromObj Green.AgileMapper.Test.StudenDo collection;
        /// </summary>
        /// <param name="form">Green.AgileMapper.Test.StudenDto collection</param>
        /// <param name="domainObj">Green.AgileMapper.Test.StudenDo collection</param>        
        public static List<Green.AgileMapper.Test.StudenDto> Warp(this IList< Green.AgileMapper.Test.StudenDo> domainObj)
        {
            List<Green.AgileMapper.Test.StudenDto> froms = new List<Green.AgileMapper.Test.StudenDto>();
            domainObj.ToList().ForEach(t =>
            {
                froms.Add(Warp(t));
            });
            return froms;
        }

        /// <summary>
        /// Green.AgileMapper.Test.StudenDto collection Warp domainObj Green.AgileMapper.Test.StudenDo collection;
        /// </summary>
        /// <param name="fromObj">Green.AgileMapper.Test.StudenDto collection</param>
        /// <param name="domainObj">Green.AgileMapper.Test.StudenDo collection</param>      
         public static void Warp(this IList<Green.AgileMapper.Test.StudenDto> fromObj, IList<Green.AgileMapper.Test.StudenDo> domainObj)
         {
               fromObj.Warp(domainObj,(fromObjItem,domainObjItem) => fromObjItem.ID == domainObjItem.ID && domainObjItem.ID != 0,false);
         }   

        /// <summary>
        /// Green.AgileMapper.Test.StudenDto collection Warp domainObj Green.AgileMapper.Test.StudenDo collection;
        /// </summary>
        /// <param name="fromObj">Green.AgileMapper.Test.StudenDto collection</param>
        /// <param name="domainObj">Green.AgileMapper.Test.StudenDo collection</param>
        /// <param name="isDeleteNotInFromItem">Delete the item that not in From collection</param>           
         public static void Warp(this IList<Green.AgileMapper.Test.StudenDto> fromObj, IList<Green.AgileMapper.Test.StudenDo> domainObj,bool isDeleteNotInFromItem)
         {
               fromObj.Warp(domainObj,(fromObjItem,domainObjItem) => fromObjItem.ID == domainObjItem.ID && domainObjItem.ID != 0,isDeleteNotInFromItem);
         }   

        /// <summary>
        /// Green.AgileMapper.Test.StudenDto collection Warp domainObj Green.AgileMapper.Test.StudenDo collection;
        /// </summary>
        /// <param name="fromObj">Green.AgileMapper.Test.StudenDto collection</param>
        /// <param name="domainObj">Green.AgileMapper.Test.StudenDo collection</param>
        /// <param name="equalPredicate">the from item equal to item expression</param>           
         public static void Warp(this IList<Green.AgileMapper.Test.StudenDto> fromObj, IList<Green.AgileMapper.Test.StudenDo> domainObj,Func<Green.AgileMapper.Test.StudenDto, Green.AgileMapper.Test.StudenDo, bool> equalPredicate)
         {
               fromObj.Warp(domainObj,equalPredicate,false);
         }   

        /// <summary>
        /// Green.AgileMapper.Test.StudenDto collection Warp domainObj Green.AgileMapper.Test.StudenDo collection;
        /// </summary>
        /// <param name="fromObj">Green.AgileMapper.Test.StudenDto collection</param>
        /// <param name="domainObj">Green.AgileMapper.Test.StudenDo collection</param> 
        /// <param name="equalPredicate">the from item equal to item expression</param>      
        /// <param name="isDeleteNotInFromItem">Delete the item that not in From collection</param>     
         public static void Warp(this IList<Green.AgileMapper.Test.StudenDto> fromObj, IList<Green.AgileMapper.Test.StudenDo> domainObj, Func<Green.AgileMapper.Test.StudenDto, Green.AgileMapper.Test.StudenDo, bool> equalPredicate,bool isDeleteNotInFromItem)
         {
             if(fromObj==null)
             {
                return ;
             }

             if (domainObj == null)
             {
                 domainObj = new List<Green.AgileMapper.Test.StudenDo>();
             }
            
            if (isDeleteNotInFromItem)
            {
                domainObj.Where(domainObjItem => fromObj.FirstOrDefault(fromObjItem => equalPredicate(fromObjItem, domainObjItem)) == null)
                    .ToList().ForEach(t =>
                    {
                        domainObj.Remove(t);
                    });
            }

             fromObj.ToList().ForEach(fromObjItem =>
             {
                 Green.AgileMapper.Test.StudenDo toItem = default(Green.AgileMapper.Test.StudenDo);
                 if (equalPredicate != null)
                 {
                     toItem = domainObj.SingleOrDefault(domainObjItem => equalPredicate(fromObjItem,domainObjItem));
                 }
                 if (toItem == null)
                 {
                     toItem = new Green.AgileMapper.Test.StudenDo();
                     domainObj.Add(toItem);
                 }
                 Warp(fromObjItem, toItem);
             });
                      
         }
    }
}